package com.xiashitech.agent.instrumentation.utils;

import com.xiashitech.agent.config.StartConfig;
import com.xiashitech.agent.utils.LocalMachineUtil;
import io.opentelemetry.javaagent.shaded.io.opentelemetry.api.common.AttributesBuilder;

public class MachineAttributesUtil {
    /**
     * 填充本机环境相关属性
     * @param attributesBuilder
     */
    public static void fillMachineAttributes(AttributesBuilder attributesBuilder) {
        try {
            attributesBuilder.put("xs.machine.ipv4s", LocalMachineUtil.getlocalIpv4s().toArray(new String[LocalMachineUtil.getlocalIpv4s().size()]));
            attributesBuilder.put("xs.machine.ipv6s", LocalMachineUtil.getlocalIpv6s().toArray(new String[LocalMachineUtil.getlocalIpv6s().size()]));
            attributesBuilder.put("xs.machine.ipv4HostNames", LocalMachineUtil.getIpv4HostNames().toArray(new String[LocalMachineUtil.getIpv4HostNames().size()]));
            attributesBuilder.put("xs.machine.ipv6HostNames", LocalMachineUtil.getIpv6HostNames().toArray(new String[LocalMachineUtil.getIpv6HostNames().size()]));
            attributesBuilder.put("xs.machine.osName", LocalMachineUtil.getOsName());
            attributesBuilder.put("xs.machine.osArch", LocalMachineUtil.getOsArch());
            attributesBuilder.put("xs.machine.osVersion", LocalMachineUtil.getOsVersion());
            attributesBuilder.put("xs.machine.userCountry", LocalMachineUtil.getUserCountry());
            attributesBuilder.put("xs.machine.machineName", LocalMachineUtil.getMachineName());
            attributesBuilder.put("xs.machine.userLanguage", LocalMachineUtil.getUserLanguage());
            attributesBuilder.put("xs.machine.userTimezone", LocalMachineUtil.getUserTimezone());
        } catch (Throwable e) {
            StartConfig.throwableStackPrinter(e);
        }
    }
}
